﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.Linq;
using System.Globalization;
using Chefbook.DataAccessLayer;

namespace Chefbook.UserActions
{
    public abstract class UserActionBase : IUserAction
    {
        private bool wasDone;

        private bool undoable = true;

        public bool IsUndoable
        {
            get { return undoable; }
            protected set { undoable = value; }
        }

        public virtual void DoAction()
        {
            if (wasDone)
                throw new InvalidOperationException(string.Format(CultureInfo.CurrentUICulture, "Cannot redo action that wasn't undone: (0)", this));
            wasDone = true;
        }

        public virtual void UndoAction()
        {
            if (!wasDone)
                throw new InvalidOperationException(string.Format(CultureInfo.CurrentUICulture, "Cannot undo action that wasn't done: (0)", this));
            if (!undoable)
                throw new InvalidOperationException(string.Format(CultureInfo.CurrentUICulture, "Action '{0}' is not undoable", this.ToString()));
            wasDone = false;
        }

        public ChefbookEntities DatabaseConnector { get; set; }
    }
}
